package _go

//常规两次循环 暴力破解 时间复杂度为 N方
//执行时间和内存	4 ms	3 MB	Go
func twoSum(nums []int, target int) []int {

	var i int
	var res []int
	for k,v := range nums{

		for i=k+1; i<len(nums);i++{
			//加操作要比减操作少一次补码转化
			if nums[i] + v == target {
				res = []int{k,i}
				break
			}
		}
	}
	return  res
}

//加入hashmap 时间复杂度降低 为2N
//执行时间和内存	4 ms	4.3 MB	Go
func twoSum1(nums []int, target int) []int {

	res := make(map[int]int)
	for k1,v := range nums{
		res[ target - v] = k1
	}
	for k,val := range nums{
		if( k!= res[val] && res[val] != 0 ){
			return []int{k,res[val]}
		}
	}
	return  []int{}
}
